package mvc;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;


import org.geom.Point2D;
import org.geom.Point3D;


public class SurfaceControllerMouse3D 
implements MouseListener, MouseMotionListener, KeyListener{

	public static boolean mousePressed = false;

	protected enum Action { ROTATE, TRANSLATE, SCALE };
	protected Action action = Action.TRANSLATE;

	protected Point2D mouseDown;// = new Point2D();
	protected int deltax;
	protected int deltay;


	protected ViewSurface view;
	
	public SurfaceControllerMouse3D(ViewSurface view) {
		this.view = view;
	}

	@Override
	public void mouseDragged(MouseEvent e) {

		deltax = e.getX() - (int)mouseDown.x;
		deltay = e.getY() - (int)mouseDown.y;
		
		mouseMoved(e);

		switch(action) {
		case SCALE: 
			view.setScale(new Point3D(deltay, deltay,0));
			break;
		case TRANSLATE: 
			view.setTranslate(new Point3D(deltax, deltay,0));
			break;
		case ROTATE:
			view.setRotate(new Point3D(deltax, deltay,0));
			break;
		}

		view.repaint();
	}

	
	@Override
	public void keyPressed(KeyEvent e) {
		
		char c = e.getKeyChar();
		if ( c=='t' || c=='T') action = Action.TRANSLATE;
		if ( c=='r' || c=='R') action = Action.ROTATE;
		if ( c=='s' || c=='S') action = Action.SCALE;
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	@Override
	public void mouseMoved(MouseEvent e) {
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		mouseDown = new Point2D(e.getX(), e.getY());
		
		view.setFocusable(true);
		view.requestFocus();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}


}